import { createSlice, type PayloadAction } from '@reduxjs/toolkit'
import type { UserState } from './types'

const INIT_STATE: UserState = {
  username: '',
  nickname: '',
}

export const userSlice = createSlice({
  name: 'user',
  initialState: INIT_STATE,
  reducers: {
    loginReducer: (state: UserState, action: PayloadAction<UserState>) => {
      return {
        ...state,
        ...action.payload,
      }
    },
    logoutReducer: () => INIT_STATE,
  },
})

export const userAction = userSlice.actions

export default userSlice.reducer
